package com.xpalive.base.dto.page;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xpalive.base.dto.page.impl.PageRspImpl;

public class MyBatisPageAdapter {

    public static <T> PageRsp<T> convert(IPage<T> page) {
        PageRspImpl<T> xPageImpl = new PageRspImpl<>();
        xPageImpl.setTotalPage(page.getPages());
        xPageImpl.setTotal(page.getTotal());
        xPageImpl.setSize(page.getSize());
        xPageImpl.setPage(page.getCurrent());
        xPageImpl.setContent(page.getRecords());
        return xPageImpl;
    }

    public static <T> IPage<T> convert(PageReq pageReq) {
        Page page = new Page(pageReq.page, pageReq.getSize());
        return page;
    }
}
